/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.satyam.swingvalidator.commons;

import javax.swing.JComponent;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.satyam.swingvalidator.core.Severity;
import com.satyam.swingvalidator.core.AbstractValidator;

public class PasswordStrengthValidator extends AbstractValidator {

    public PasswordStrengthValidator() {
    }

    @Override
    protected Severity getValidationCriteria(JComponent c) {
        String password = null;
        if (c instanceof JTextField) {
            password = ((JTextField) c).getText();
        } else if (c instanceof JPasswordField) {
            password = new String(((JPasswordField) c).getPassword());
        }
        
        if (password.length() <= 4) {
            return new Severity(Severity.ERROR, "Error");
        } else if (password.length() < 8) {
            return new Severity(Severity.WARNING, "Password is very weak!");
        } else {
            return new Severity(Severity.NO_ERROR, "");
        }
    }
}
